function teacherLogin() {
  layui.use(['element', 'form', 'layer'], () => {
    let form = layui.form,
        layer = layui.layer;
    form.on('submit(teaLogin)', obj => {
      let field = obj.field;
      if (field.teaNo.trim() === '') {
        layer.msg('请输入职工号');
      } else {
        $.get({
          url: '/teacher/queryByNoAndPwd',
          data: field,
          success: teacher => {
            if (teacher !== '') {
              localStorage.setItem('teacherNo', teacher.teacherNo);
              localStorage.setItem('name', teacher.name);
              layer.msg('登录中······');
              setTimeout(() => {
                if (teacher.isAdmin === 1)
                  window.location.href = '/teacher-action/student';
                else
                  window.location.href = '/teacher-action/check';
              })
            } else {
              alertInfo('职工号或密码输入错误');
            }
          },
          error: function () {
            alertInfo('系统出现异常，请联系管理员');
          }
        });
      }
    });
    form.on('submit(stuLogin)', obj => {
      let field = obj.field;
      $.get(`${app.urlLocation.queryStuByNoAndPwd}`, field, res => {
        if (res === 200) {
          layer.msg('登录成功，正在进行跳转');
          setTimeout(() => {
            window.location.href = '/student-action/index';
          }, 1000)
        } else {
          layer.msg('学号或密码错误');
        }
      })
    })
  })
}

$('.forget-password a').click(function () {
  window.location.href = '/forgot';
});

function alertInfo(info) {
  layui.use('layer', function () {
    layui.layer.msg(info)
  })
}